Skip to content

Conversation

@euanh
Copy link
Collaborator

@euanh euanh commented Dec 12, 2024

Motivation

In the 'Post then Put' blob upload method
(https://github.com/opencontainers/distribution-spec/blob/main/spec.md#post-then-put)
the client starts by making a POST request asking the registry to
start an upload session. The registry responds with a URL to which
the client should PUT the blob. The upload location might not be
provided by the registry server, allowing the registry to offload
storage to a different service.

Until now all registries we have encountered have returned absolute
upload URLs, however GHCR returns a relative URL causing uploads to
fail as reported in #43.

Modifications

If the registry returns a relative URL, startBlobUpload() rewrites it
to be an absolute URL referring to the registry.

Result

Images can be pushed to GHCR and other registries which return relative
upload locations.

Test Plan

Automated tests continue to pass.
Tested manually with GHCR and other known registries.

Fixes: #43

… return value

URL's .appending(queryItems:) method can be used to append the
digest to the upload location URL;  URLComponents is not needed.
.appending(queryItems:) always succeeds, so we do not need to
check for nil in putBlob() and can instead throw in startBlobUploadSession
if necessary.
Motivation
----------

In the 'Post then Put' blob upload method
(https://github.com/opencontainers/distribution-spec/blob/main/spec.md#post-then-put)
the client starts by making a POST request asking the registry to
start an upload session.   The registry responds with a URL to which
the client should PUT the blob.   The upload location might not be
provided by the registry server, allowing the registry to offload
storage to a different service.

Until now all registries we have encountered have returned absolute
upload URLs, however GHCR returns a relative URL causing uploads to
fail as reported in apple#43.

Modifications
-------------

If the registry returns a relative URL, startBlobUpload() rewrites it
to be an absolute URL referring to the registry.

Result
------

Images can be pushed to GHCR and other registries which return relative
upload locations.

Test Plan
---------

Automated tests continue to pass.
Tested manually with GHCR and other known registries.

Fixes: apple#43
@euanh euanh marked this pull request as ready for review December 12, 2024 17:25
@euanh euanh merged commit 91f9b49 into apple:main Dec 12, 2024
17 checks passed
@euanh euanh deleted the fix-relative-upload-locations branch December 12, 2024 17:25
@euanh euanh added kind/bug Something isn't working semver/patch No public API change. area/interoperability Improvements to compatibility with other systems. labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/interoperability Improvements to compatibility with other systems. kind/bug Something isn't working semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTPTypesFoundation/HTTPRequest+URL.swift:126: Precondition failed: Schemeless URL is not supported

1 participant